package com.fish.user.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fish.common.constant.QueryPage;
import com.fish.common.dao.BaseIbatisDao;
import com.fish.user.po.Menus;
import com.fish.user.po.User;

public class MenusDAO extends BaseIbatisDao{
	private static final Log loger = LogFactory.getLog(MenusDAO.class);
	public MenusDAO() {
		super();
	}

	/**
	 * 根据主键查询
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public Menus queryMenusByPrimaryKey(String menusId) {
		loger.debug("queryMenusByPrimaryKey:" + menusId);
		return (Menus) this.getSqlMapClientTemplate().queryForObject("MENUS.selectByPrimaryKey", menusId);
	}

	/**
	 * 模糊查询
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	@SuppressWarnings("unchecked")
	public List<Menus> queryMenusByObject(Menus menus) {
		return (ArrayList<Menus>) this.getSqlMapClientTemplate().queryForList("MENUS.queryByMenus", menus);
	}

	/**
	 * 添加
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public void addMenus(Menus menus) {
		this.getSqlMapClientTemplate().insert("MENUS.insert", menus);
	}
	
	/**
	 * 修改
	 * 
	 * @update zhangzhenhua 2010-9-20
	 */
	public void updateMenus(Menus menus) {
		this.getSqlMapClientTemplate().update("MENUS.updateByPrimaryKeySelective", menus);
	}
	
	public Long queryMenusCountByObject(Menus menus){
		return  (Long) this.getSqlMapClientTemplate().queryForObject("MENUS.countMenusWithPaging", menus);
	}
	
	public  List<Menus> queryMenusByObject(Menus menus,QueryPage queryPage){
		menus.setBeginItem(queryPage.getBeginItem());
		menus.setEndItem(queryPage.getPageSize());
		return (List<Menus>) this.getSqlMapClientTemplate().queryForList("MENUS.selectMenusWithPaging", menus);
	}

	public List<Menus> queryMenusByUser(User userDB) {
		return (List<Menus>) this.getSqlMapClientTemplate().queryForList("MENUS.queryMenusByUser", userDB);
	}
	
}